use std::fmt;
use std::fmt::Display;
use owo_colors::OwoColorize;
use ansi_term::Colour::{Red,Green, Yellow, Blue, Purple, Cyan};

fn main() {
    // let word = "hello";
    // let mut world2="world";
    // world2="hello big world";
    // println!("{}, world", world2);
    // println!("{0}, this is {1}. {1}, this is {2}", "Alice", "Bob","lucy");
    // println!("{who} {does} {what}",does="are",who="we",what="friends");
    // println!("{}用二进制表示为{0:b}", 2);
    // println!("{number:>width$}",number=1,width=10);
    // println!("{0:>01$}",1,10);
    // //显示浮点数的位数
    // println!("Pi is roughly {PI:.4}",PI=3.14159253);
    //
    // #[derive(Debug)]
    // struct Number(i8);
    // println!("{:?}",Number(2));

    println!("{}",Strawberry(12));

    let c= Complex{
        real:3.3,
        imag:7.2
    };

    println!("Display: {}",c.red());
    println!("Display: {:?}",c.yellow());

    let arr=List(vec![2,7]);

    println!("{}",arr.green());

    for color in [
       Color {red:128, green: 255,blue:90},
       Color {red:0,green:3,blue:254},
        Color{red:0,green:0,blue:0},
    ].iter(){
        println!("{} {}",*color,Green.paint("success"));
    }

    let isOpen =true;
    let num_float:f64=1.0;

    let default_float =3.0;
    let default_integer=7;

    let mut inferred_type=12;
    inferred_type=4294967296i64;

    let mut mutable =12;
    mutable=21;
    let mutable=true;

    let an_integer=5i32;

    let tuple_a=(2,3,4,'a');
    println!("tuple_a的第二个值为：{}",tuple_a.1);

}

struct Strawberry(i32);

#[derive(Debug)]
struct Complex{
    real:f32,
    imag:f32
}

impl  fmt::Display for Strawberry {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        return  write!(f,"I have eat {} 🍓 🍓 🍓 🍓 🍓 🍓.",self.0);
    }
}

impl fmt::Display for Complex{
    fn fmt(&self,f:&mut fmt::Formatter) -> fmt::Result{
        return write!(f,"{} +{}i",self.real,self.imag);
    }
}

struct List(Vec<i32>);

impl fmt::Display for List{
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
      let vec=&self.0;

        write!(f,"[")?;
        for(index,value) in vec.iter().enumerate(){
            if index!=0{
                write!(f,",")?;
            }
            write!(f,"{}:{}",index,value)?;
        }
        return write!(f,"]");
    }
}

struct Color{
    red:u8,
    green:u8,
    blue:u8
}

impl Display for Color{
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
      return  write!(f,"RGB ({r},{g},{b}) 0x{r:0w$X} {g:0w$X} {b:0w$X}",
          r=self.red,
          g=self.green,
          b=self.blue,
          w=2);
    }
}


